/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simplemetrosystem.control.Calculation;

import java.util.logging.Level;
import java.util.logging.Logger;
import simplemetrosystem.view.InformationPane;
import simplemetrosystem.view.MetroFrame;
import simplemetrosystem.view.canvas.CanvasModel;
import simplemetrosystem.view.table.Exceptions.InformationPanelException;

/**
 *
 * @author Eric Qian
 */
public class ModelManager {

    public static ModelManager getInstance() {
        return modelManager;
    }

    public static ModelManager newInstance(MetroFrame frame) {
        modelManager = new ModelManager(frame);
        return modelManager;
    }

    public ModelManager(MetroFrame frame) {
        this.frame = frame;
        model = false;
    }

    public void setModel(boolean model) {
        if (this.model != model) {
            CanvasModel.getInstance().cancelSelect();
            frame.getFloorBar().setModel(model);
            frame.getEditToolBar().setModel(model);
            frame.getSystemToolBar().setModel(model);
            frame.getMetroMenuBar().setModel(model);
            if (model) {
                frame.getMetroTabbedPane().getAllLineCanvas().setCalculHandler();
            } else {
                frame.getMetroTabbedPane().getAllLineCanvas().setSelectingMouseHandler();
            }
            this.model = model;
            if (!model) {
                try {
                    frame.getInfPane().setFocus(InformationPane.ALL_LINE, null);
                } catch (InformationPanelException ex) {
                    Logger.getLogger(ModelManager.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    private static ModelManager modelManager;
    private MetroFrame frame;
    private boolean model;
}
